<?php
/**
 * Created by PhpStorm.
 * User: ly
 * Date: 2018\1\3 0003
 * Time: 18:21
 */
use common\models\UserModel;
use yii\helpers\Url;
use yii\widgets\LinkPager;
use common\models\Country;
$this->title = "项目管理";
$getData=Yii::$app->request->get();

$this->registerCssFile('@web/css/select2.min.css', ['depends' => ['backend\assets\AppAsset'], 'position' => $this::POS_HEAD]);

?>
<link rel="stylesheet" type="text/css" href="/css/single-project-management.css"/>


<style type="text/css">
	.pagination {
    /*display: block;
    margin-left: 50%;
    transform: translateX(-50%);*/
    }
    .wrap > .container-fluid > .container {
        /*width: 100%!important;*/
       padding: 0;
    }
    /*//分页*/
   .pagination {
   		position: absolute;
   		left: 50%;
   		transform: translateX(-50%);
   		margin-left: 0px;
   }
   
   .myBagSeachBox .container {
   	padding-bottom: 70px;
   }

    /** 联想搜索 **/
    .select2-results__message{display: none;}
    .myBagSeachBox .queryBox .zichanleixing {  margin-left: 0; margin-top: 20px;  }
</style>
<!--一键置 顶-->
<a href="#" class="clicktop" title="返回顶部">
	<!--<img src="image/common/clickTop.png" alt=""  />-->
</a>
<!--一键置 顶结束-->
<!--资产包详情搜索部分和列表开始-->
<div class="myBagSeachBox">
    <form name="projectQuery" id="projectQuery" method="get">
    <div class="container">
        <div class="top">
            <a href="<?php  echo Url::toRoute('/site/index',true);?>">办公大厅</a> >
   <!--
        <a href="<?php // echo Url::toRoute('/project',true);?>">项目管理</a> > 
         --> 
            <a href="jascript:;" class="pagedetails">项目管理</a>
        </div>

        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade in active" id="myPortfolioPackage">
                <div class="box">
                    <input class="search" list="assetPackageTitle" name="keyWords" value="<?php echo Yii::$app->request->get('keyWords','');?>" type="search" placeholder="请输入资产包/项目名称的关键词"/>
                    <input type="hidden" name="is_highlights" id="is_highlights" value="<?php echo Yii::$app->request->get('is_highlights','');?>">
                    <span class="dianLiang pull-right">
							<strong class="img <?php echo Yii::$app->request->get('is_highlights','')==1?'trueOff':'';?>">
							</strong>
							<span class="pull-right">只显示亮点项目</span>
							<div class="shouqi">
								 收起查询条件
							</div>
							<div class="zhankai">
								 展开查询条件
							</div>
						</span>
                    <datalist id="assetPackageTitle">

                    </datalist>
                </div>
            </div>
        </div>
        <div class="queryBox">
            <label for="" class="benjin">本金数额
                <select name="principal">
                    <option value="">全部</option>
                    <option value="1" <?php echo Yii::$app->request->get('principal','')==1?'selected':''?>>100万以下</option>
                    <option value="2" <?php echo Yii::$app->request->get('principal','')==2?'selected':''?>>100-1000万</option>
                    <option value="3" <?php echo Yii::$app->request->get('principal','')==3?'selected':''?>>1000-5000万</option>
                    <option value="4" <?php echo Yii::$app->request->get('principal','')==4?'selected':''?>>5000-1 亿</option>
                    <option value="5" <?php echo Yii::$app->request->get('principal','')==5?'selected':''?>>1 亿以上</option>
                </select>
            </label>
            <label for="" class="zichanbaobei">抵押物类型
                <select name="mortgage_type">
                    <option value="">全部</option>
                    <?PHP
                    $selected='';
                    $InvestigationMortgageType=Yii::$app->params['InvestigationMortgageType'];
                    foreach ($InvestigationMortgageType as $key=>$val){
                        if(isset($getData['mortgage_type']))
                            $selected=($key==$getData['mortgage_type']?'selected':'');
                        echo '<option value="'.$key.'" '.$selected.'>'.$val.'</option>';
                    }
                    ?>
                </select>
            </label>
            <label for="" class="dangqian">当前状态
                <select name="status">
                    <option value="">全部</option>
                    <?PHP
                    $project_state=Yii::$app->params['project_state'];
                    $selected='';
                    foreach ($project_state as $key=>$val){
                        if(empty($key)|| $key==2 ||$key==3) continue;
                        if(isset($getData['status']))
                            $selected=($key==$getData['status']?'selected':'');
                        echo '<option value="'.$key.'"  '.$selected.'>'.$val.'</option>';
                    }

                    ?>
                </select>
                <!--<input type="search" list="dangqianzhuantian"/>-->
            </label>
            <label for="" class="zichanleixing">项目类型
                <!--<input type="search" list="zichanleixing"/>-->
                <select name="type2">
                    <option value="">全部</option>
                    <?PHP
                    $projectCategory=Yii::$app->params['projectCategory'];
                    $selected='';
                    foreach ($projectCategory as $key=>$val){
                        if($key>0){
                            if(isset($getData['type2']))
                                $selected=$key==$getData['type2']?'selected':'';
                            echo '<option value="'.$key.'" '.$selected.'>'.$val['name'].'</option>';
                        }
                    }
                    ?>
                </select>
            </label>
            <label for="" class="shangchuanren">
                项目经理
                <input list="tuandui" name="owner" value="<?php echo isset($getData['owner'])?$getData['owner']:'';?>"/>
            </label>
<!--            <datalist id="shangchuanren">-->
<!--                <option value="1">155</option>-->
<!--                <option value="2">2ll;</option>-->
<!--                <option value="3">3</option>-->
<!--            </datalist>-->
            <label for="" class="formBox clearfix">
                <label class="shenglabel" for="">省份地区</label>
                <select class="sheng" name="province" id="provinceList">
                    <option value="">全部</option>
                    <?PHP
                        $province=Country::getProvince();
                        $selected='';
                        foreach ($province as $val){
                            if(isset($getData['province']))
                                $selected=$val['id']==$getData['province']?'selected':'';
                            echo '<option value="'.$val['id'].'" '.$selected.'>'.$val['title'].'</option>';
                        }
                    ?>
                </select>&nbsp;&nbsp;省
                <select class="shi" name="city" id="cityList">
                    <option value="">全部</option>
                    <?php
                          if(isset($getData['province']) && $getData['province']>0){
                              $city=Country::getProvince((int)$getData['province']);
                              $selected='';
                              foreach ($city as $val){
                                  if(isset($getData['city']))
                                        $selected=$val['id']==$getData['city']?'selected':'';
                                  echo '<option value="'.$val['id'].'" '.$selected.'>'.$val['title'].'</option>';
                              }
                          }
                    ?>
                </select>&nbsp;&nbsp;市
            </label>
            <label for="" class="tuandui">项目总监
                <input type="search" list="tuandui" value="<?php echo isset($getData['manager'])?$getData['manager']:'';?>" name="manager"/>
            </label>
            <datalist id="tuandui">
                <?php
                    foreach ($users as $user){
                        echo '<option value="'.$user['realname'].'">'.$user['realname'].'</option>';
                    }
                ?>
            </datalist>
            <label for="" class="zongjian">团队成员
                <input type="search" list="tuandui" name="partner" value="<?php echo isset($getData['partner'])?$getData['partner']:'';?>" title="未测试"/>
            </label>
<!--            <datalist id="zongjian">-->
<!--                <option value="1">1</option>-->
<!--                <option value="2">2</option>-->
<!--                <option value="3">3</option>-->
<!--            </datalist>-->
            <label for="" class="suSong">诉讼状态
                <select name="is_suit" class="pull-right">
                    <option value="">全部</option>
                    <?php
                    $isSuit = Yii::$app->params['isSuit'];
                    foreach ($isSuit as $k => $v){
//                        if ($k>=0){
                            $is_suit =(isset($getData['is_suit'])&&$getData['is_suit']!=''&&$getData['is_suit']==$k)?'selected':'';
                            $name = $v['name'];
                            echo '<option value="'.$k.'"  '.$is_suit.'>'.$name.'</option>';
//                        }
                    }
                    ?>
                </select>
            </label>
        </div>
        
        <div class="chaXun">
        	<input type="reset" onclick="window.location.href='/project'" value="清除查询条件"  class="reset pull-right"/>
            <input class="pull-right" id="chaxun" type="submit" value="查询"/>
        </div>
        <div class="row">
            <!--<div class="top zuChengBox  clearfix">
                <buttont class="myactive pull-left ">组成新包</buttont>
            </div>-->
            <?PHP if(count($data)>0) { ?>
                <table class="mytable  tableRaiusTh" border="0" cellspacing="0" cellpadding="0">
                    <thead class="thead-normal">
                    <tr class="top tableTh">
                        <th class="quagXuan">
                            <input type="checkbox" name="" id="" value=""/>
                        </th>
                        <!--                    <th class="input">项目编号</th>-->
                        <th class="bianhao" sort="borrower">借款人名称</th>
                        <th class="name" sort="city">省份地区</th>
                        <th class="diqv" sort="principal">本金</th>
                        <th class="benjin" sort="is_suit">诉讼状态</th>
                        <th class="benjin" sort="management_status">经营状况</th>
                        <th class="lixi" sort="type2">项目类型</th>
                        <th class="shengyu" sort="title">隶属资产包</th>
                        <th class="shengfen" sort="realname">项目经理</th>
                        <!--<th class="upload">团队成员</th>-->
                        <th class="uploadTime" sort="guarantor">保证/抵押人</th>
                        <th class="dangqian" sort="status">当前状态</th>
                        <th class="jindiao" sort="highlights">亮点明细</th>
                        <th class="xiangqing">详情</th>
                    </tr>
                    </thead>
                    <thead class="thead-fixed" style="display:none ;">
                    <tr class="top tableTh">
                        <th class="quagXuan">
                            <input type="checkbox" name="" id="" value=""/>
                        </th>
                        <!--                    <th class="input">项目编号</th>-->
                        <th class="bianhao" sort="borrower">借款人名称</th>
                        <th class="name" sort="city">省份地区</th>
                        <th class="diqv" sort="principal">本金</th>
                        <th class="benjin" sort="is_suit">诉讼状态</th>
                        <th class="benjin" sort="management_status">经营状况</th>
                        <th class="lixi" sort="type2">项目类型</th>
                        <th class="shengyu" sort="title">隶属资产包</th>
                        <th class="shengfen" sort="realname">项目经理</th>
                        <!--<th class="upload">团队成员</th>-->
                        <th class="uploadTime" sort="guarantor">保证/抵押人</th>
                        <th class="dangqian" sort="status">当前状态</th>
                        <th class="jindiao" sort="highlights">亮点明细</th>
                        <th class="xiangqing">详情</th>
                    </tr>
                    </thead>
                    <?PHP
                    $isSuit = Yii::$app->params['isSuit'];
                    $projectCategory = Yii::$app->params['projectCategory'];
                    $borrowerStates = Yii::$app->params['borrowerStates'];
                    //                    $userModel=new UserModel();
                    foreach ($data as $val) {
                        // $val['code']=empty($val['code'])?'无':$val['code'];<td class="txt"><strong title="D17OO-SX15-0099" class="txt-cut">'.$val['code'].'</strong></td>
//                     	                  团队成员          <td><span class="txt-cut" title="'.$val['team']['user']['realname'].'">'.$val['team']['user']['realname'].'</span></td>
                        $highlight = $val['is_highlights'] == 1 ? 'highlights.png' : 'highlights2.png';
                        //$partner=$userModel->getUserStrNdepartment($val['team']['partner']);
                        $isView = \backend\controllers\DtActionFilter::checkProject('project_view', $val['id']);
                        if ($isView) {
                            $showPower = '<a target="_blank" href="/project/getinfodata?package_id=' . $val['package_id'] . '&project_id=' . $val['id'] . '">查看</a>';
                            $browerShow = 'target="_blank" href="/project/getinfodata?package_id=' . $val['package_id'] . '&project_id=' . $val['id'] . '"';
                        } else {
                            $showPower = '<a href="javascript:void(0)" class="fangwenSQ" data-packageid=' . $val['id'] . ' data-title=' . $val['borrower'] . '>申请访问</a>';
                            $browerShow = 'href="javascript:void(0)" class="fangwenSQ" data-packageid=' . $val['id'] . ' data-title=' . $val['borrower'];
                        }
                        $isView_package = \backend\controllers\DtActionFilter::checkPackage('package_view', $val['package_id']);
                        if ($isView_package) {
                            $show_package = '/package/detail-info?packageid=' . $val['package_id'];
                        } else {
                            $show_package = 'javascript:void(0)';
                        }
                        echo '<tr>
	                            <td><input type="checkbox" name="checkboxID"  value="' . $val['id'] . '" class="pull-left" title=""/>
	                                <span class="pull-right"><img class="xy" src="/image/projectManagement/' . $highlight . '"></span>
	                             </td>
	                            <td title="' . $val['borrower'] . '"><a ' . $browerShow . '"><span class="txt-cut" >' . $val['borrower'] . '</span></a></td>
	                            <td title="' . $val['province'] . $val['city'] . '">
	                            	<span class="txt-cut" >' . $val['province'] . $val['city'] . '</span>
	                            </td>
	                            <td title="' . Yii::$app->formatter->asDecimal($val['principal']) . '">
	                            	<span class="txt-cut" >' . Yii::$app->formatter->asDecimal($val['principal']) . '</span>
	                            </td>
	                            <td title="' . $isSuit[$val['is_suit']]['name'] . '">
                                    <span class="txt-cut" >' . $isSuit[$val['is_suit']]['name'] . '</span>
	                            </td>
	                            <td title="">
	                            	<span class="txt-cut" >' . ($val['management_status'] > 0 ? $borrowerStates[$val['management_status']]['name'] : '无') . '</span>
	                            </td>
	                            <td title="' . ($val['type2'] > 0 ? $projectCategory[$val['type2']]['name'] : '无') . '">
	                            	<span class="txt-cut" >' . ($val['type2'] > 0 ? $projectCategory[$val['type2']]['name'] : '无') . '</span>
	                            </td>
	                            <td title="' . $val['title'] . '">
	                            	<a target="_blank" href="' . $show_package . '">
	                            		<span class="txt-cut" >' . $val['title'] . '</span>	
	                            	</a>
	                            </td>
	                            <td title="' . $val['realname'] . '">
	                            	<span class="txt-cut" >' . $val['realname'] . '</span>
	                            </td>
	                            <td title="' . $val['guarantor'] . '">
	                            	<span class="txt-cut" >' . $val['guarantor'] . '</span>
	                            </td>
	                            <td title="' . $project_state[$val['status']] . '">
	                            	<span class="txt-cut project " >' . $project_state[$val['status']] . '</span>
	                            </td>
	                            <td title="' . $val['highlights'] . '">
	                            	<span class="txt-cut" >' . $val['highlights'] . '
	                            </td>
	                            <td>' . $showPower . '</td>
	                        </tr>';
                    }
                    ?>
                </table>
                <?PHP
                echo LinkPager::widget([
                    'pagination' => $pages,
                    'firstPageLabel' => '首页',
                    'lastPageLabel' => '尾页',
                    'nextPageLabel' => '下一页',
                    'prevPageLabel' => '上一页'
                ]);
                ?>
                <div style="float: right;margin: 25px;">
<!--                <form action="--><?php //echo $_SERVER['REQUEST_URI'] ;?><!--"  method="get" class="pageTotal" id="pageSizeForm">-->
                    <span class="lf">每页显示</span>
                    <select class="pane" name="per-page" id="per-page" onchange="$('#projectQuery').submit();">
                        <option value="10" <?php echo $pages->pageSize==10?'selected':'';?>>10</option>
                        <option value="20" <?php echo $pages->pageSize==20?'selected':'';?>>20</option>
                        <option value="30" <?php echo $pages->pageSize==30?'selected':'';?>>30</option>
                        <option value="40" <?php echo $pages->pageSize==40?'selected':'';?>>40</option>
                        <option value="50" <?php echo $pages->pageSize==50?'selected':'';?>>50</option>
                    </select>条
<!--                </form>-->
                <span class="totalSize">共<?php echo $pages->totalCount;?></span>条记录
                </div>
            <?php
            }else{
                echo '<div class="defaultPage" style="margin-top: 40px;">
                    <div class="defaultPage-nothing">
                        <img src="/image/defaultPage/nothing.png" style="width:100%">
                    </div>
                </div>';
            }
            ?>
        </div>
    </div>
    </form>
</div>
<!-- Modal -->
<div class="modal fade" id="shenqingFW" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <?= $this->render('../my-package/fangwen');?>
</div>
<!-- 模态窗口  结束!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
    <!--资产包详情搜索部分结束-->
    <!--资产包详情列表结束-->
    <!--    <script type="text/javascript" src="/js/jquery.min.js" ></script>-->
    <!--    <script type="text/javascript" src="/js/common.js" ></script>-->
    <!--    <script type="text/javascript" src="/js/bootstrap.min.js"></script>-->
    <!--//本页js样式-->
    <script type="text/javascript" src="/js/single-project-management.js"></script>
    <script type="text/javascript" src="/js/select2.min.js"></script>

<script type="text/javascript">
    //<span class="glyphicon glyphicon-triangle-bottom"></span>是否存在排序并调整排序后的显示
    var sortStr='<?php echo isset($getData['sort'])?$getData['sort']:'';?>';
    //表头排序可排序的用手指
    $('.tableRaiusTh thead tr th ').each(function () {
        if($(this).attr('sort')!=undefined){
            $(this).css({'cursor':'pointer'});
            if($(this).attr('sort')==sortStr){
                $(this).attr('sort','-'+sortStr);
                $(this).html($(this).html()+'<span class="glyphicon glyphicon-triangle-top"></span>');
            }else if('-'+$(this).attr('sort')==sortStr){
                $(this).html($(this).html()+'<span class="glyphicon glyphicon-triangle-bottom"></span>');
            }
        }
    })
    //表头排序
    $('.tableRaiusTh thead tr th ').click(function () {
        if($(this).attr('sort')!=undefined){
            //var newUrl=window.location.href;
            var newUrl=funcUrlDel('sort');
            if(newUrl.indexOf('?') > 0){
                window.location.href=newUrl+'&sort='+$(this).attr('sort');
            }else{
                window.location.href=newUrl+'?sort='+$(this).attr('sort');
            }
        }
    })
    // 删除url中某个参数,并跳转
    function funcUrlDel(name){
        var loca = window.location;
        var baseUrl = loca.origin + loca.pathname + "?";
        var query = loca.search.substr(1);
        if (query.indexOf(name)>-1) {
            var obj = {}
            var arr = query.split("&");
            for (var i = 0; i < arr.length; i++) {
                arr[i] = arr[i].split("=");
                obj[arr[i][0]] = arr[i][1];
            };
            delete obj[name];
            var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g,"").replace(/\:/g,"=").replace(/\,/g,"&");
            return url
        }
        return window.location.href;
    }
    $('.img').click(function () {
        if($("#is_highlights").val()==1){
            $("#is_highlights").val('');
        }else{
            $("#is_highlights").val(1);
        }
        $('#projectQuery').submit();
    })
//	搜索高亮显示
	$('input').focus(function(){
		$(this).css({
			"border":"1px solid #2194f1"
		})
	})
	$('input').blur(function(){
		$(this).css({
			'border':"1px solid #e2e2e2"
		})
	})
	
	$('select').focus(function(){
		$(this).css({
			"border":"1px solid #2194f1"
		})
	})
	$('select').blur(function(){
		$(this).css({
			'border':"1px solid #e2e2e2"
		})
	})
    $('#provinceList').change(function () {
        var pid=$(this).val();
        $.ajax({
            url: "/package/get-country-list",
            data: {'id': pid},
            type: "post",
            async: false,
            dataType: "json",
            success: function (data, status) {
                var str = '<option value>请选择市</option>';
                if (data.code == 200) {
                    var content = data.data.res;//获取的内容主体
                    for (var i = 0; i < content.length; i++) {
                        str += '<option value=' + content[i].id + '>' + content[i].title + '</option>';
                    }
                }
                $('#cityList').html(str);
            }
        });
    });

    //------------------------------申请访问----fly------------------
    $(".fangwenSQ").click(function () {
        var package_id = $(this).data('packageid');
        var title = $(this).data('title');
        $("#packageId").val(package_id)
        $("#title").val(title)
        $("#shenqingFW").modal();
    })

    $("#saveFWAccess").click(function () {
        var shenqingFWNote = $("#shenqingFWNote").val();
        var packageId = $("#packageId").val();
        var title = $("#title").val();

        var url = '/package-apply/access-apply'
        $.post(url,{'packageId':packageId,'shenqingFWNote':shenqingFWNote,'is_package':2,'title':title,'group':2},function (res) {
            resData = JSON.parse(res)
            layer.msg(resData.message)
            if (resData.code == 200){
                $("#shenqingFW").modal('hide');
            }
        })
    })
    //------------------------------申请访问----fly------------------


    $(function () {
        $('#cityList').select2({
            language: "zh-CN",  //设置 提示语言
            width: '100px', //设置下拉框的宽度
            tokenSeparators: [',', ' '],
            placeholder: "全部",  //提示语
            //maximumSelectionLength :30,   //限制搜索的个数
            tags: false                //可以手动添加，若限制手动添加，设置为false
        })

        $('#provinceList').select2({
            language: "zh-CN",  //设置 提示语言
            width: '100', //设置下拉框的宽度
            tokenSeparators: [',', ' '],
            placeholder: "全部",  //提示语
            //maximumSelectionLength :30,   //限制搜索的个数
            tags: false                //可以手动添加，若限制手动添加，设置为false
        })
    })
</script>
